<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="fmt" uri="jakarta.tags.fmt" %>
<html>
<head>
    <title>用户列表</title>
    <jsp:include page="../../include.jsp"/>
    <script src="${pageContext.request.contextPath}/js/user.js"></script>
</head>
<body>
    <div class="container">
        <br>
        <jsp:include page="head.jsp"/>

        <table class="table table-hover table-bordered">
            <thead>
               <tr>
                  <th>序号</th>
                  <th>账号</th>
                  <th>密码</th>
                  <th>创建时间</th>
                  <th>是否删除</th>
                   <th>
                       <button class="btn btn-success" data-toggle="modal" data-target="#myModal">
                           添加
                       </button>

                       <button class="btn btn-info" onclick="location='user?action=export'">导出</button>
                   </th>
               </tr>
            </thead>
            <tbody>
            <c:forEach items="${pager.datas}" var="user">
            <tr>
                <td>${user.id}</td>
                <td>${user.username}</td>
                <td>${user.password}</td>
                <td>
                    ${user.create_time}
<%--                  <fmt:formatDate value="${user.create_time}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>--%>
                </td>
                <td>${user.is_del==0 ? '活动': '禁用'}</td>
                <td>
                    <img src="${pageContext.request.contextPath}/upload/${user.avatar}" width="50px" height="50px" alt="">
                </td>
                <td>

                    <button class="btn btn-warning" value="${user.id}">删除</button>
                    <button class="btn btn-info" data-toggle="modal" data-target="#myModal${user.id}">
                        修改
                    </button>
                </td>
                <div class="modal fade" id="myModal${user.id}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel">编辑用户</h4>
                            </div>
                            <form action="user?action=save" method="post" enctype="multipart/form-data">
                                <div class="modal-body">

                                    <input type="hidden" name="id" value="${user.id}">
                                        <%--                                         <input type="hidden" name="token" value="<%=System.currentTimeMillis()%>">--%>
                                    账号：<input type="text" name="username" value="${user.username}"><br>
                                    密码：<input type="text" name="password" value="${user.password}"><br>
                                    头像：<input type="file" name="pic">
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                    <button class="btn-success">提交</button>
                                </div>
                            </form>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->

            </tr>
            </c:forEach>
            <tr>
                <td colspan="10" align="center">
                    每页<select id="sel" name="pagesize">
                    <c:forEach begin="5" end="20" step="5" var="i">
                        <option value="${i}" ${pager.getPagesize() ==i ? 'selected':''}>${i}</option>
                    </c:forEach>
                </select>条。
                    ${pager.getItems()}
                    <input type="text" name="currentPage" size="2"> <input type="button" class="go" value="go">
                </td>
            </tr>

            </tbody>
        </table>
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="addModalLabel">新增用户</h4>
                    </div>
                    <form action="user?action=save" method="post" enctype="multipart/form-data">
                        <div class="modal-body">
                            账号：<input type="text" name="username" id="userName" value="${user.username}"><br>
                            密码：<input type="text" name="password" value="${user.password}"><br>
                            头像：<input type="file" name="pic"></input>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button class="btn-success">提交</button>
                        </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
    </div>
</body>
</html>
